package com.example.nfctagcommons.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.nfctagcommons.interfaces.ICustomDialogAction;
import com.example.nfctagcommons.utils.StringPool;

public class AlertDialogBuilder {
	public static void showSimpleRestartActivityDialog(final Activity activity, String title, String message, String positiveText, String negativeText, boolean cancelable, final ICustomDialogAction action){
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setTitle(title);
		builder.setMessage(message);
	    builder.setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
	    	@Override
	    	public void onClick(DialogInterface dialog, int id) {
	    		action.positiveAction();
	    	} 
	    });
	    if (negativeText != null && !negativeText.equals(StringPool.BLANK)){
	    	builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
		    	@Override
		    	public void onClick(DialogInterface dialog, int id) {
		    		action.negativeAction();
		    	} 
		    });
	    }
	    builder.setCancelable(cancelable);
	    AlertDialog dialog = builder.create();
	    dialog.show();
	}

	public static void showSimpleViewDialog(final Activity activity, View view, String title, String message, String positiveText, String negativeText, boolean cancelable, final ICustomDialogAction action){
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		builder.setTitle(title);
		builder.setView(view);
		builder.setMessage(message);
	    if (positiveText != null && !positiveText.equals(StringPool.BLANK)){
		    builder.setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
		    	@Override
		    	public void onClick(DialogInterface dialog, int id) {
		    		action.positiveAction();
		    	} 
		    });
	    }
	    if (negativeText != null && !negativeText.equals(StringPool.BLANK)){
	    	builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
		    	@Override
		    	public void onClick(DialogInterface dialog, int id) {
		    		action.negativeAction();
		    	} 
		    });
	    }
	    builder.setCancelable(cancelable);
	    AlertDialog dialog = builder.create();
	    dialog.show();
	}
	
//	public static void showNoNFC(final Activity activity, int layoutId){
//		LayoutInflater inflater = activity.getLayoutInflater();
//		View dialoglayout = inflater.inflate(layoutId,(ViewGroup) activity.findViewById(layoutId));
//		new AlertDialog.Builder(activity)
//			.setView(dialoglayout)
//			.setPositiveButton("Habilitar NFC",
//				new DialogInterface.OnClickListener(){
//					@Override
//					public void onClick(DialogInterface arg0, int arg1) {
//						activity.startActivity(new Intent(android.provider.Settings.ACTION_NFC_SETTINGS));
//					}
//				})
//			.setNegativeButton("Cerrar", new OnClickListener(){							
//				@Override
//				public void onClick(DialogInterface arg0, int arg1) {
//					activity.finish();
//				}
//			})
//			.create()
//			.show();
//	}
}
